{extend name="layout" /}
{block name="body"}
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-toolbar d-flex flex-column flex-md-row">
                <div class="toolbar-btn-action">
                    <a class="btn btn-primary m-r-5" data-toggle="modal" data-target="#exampleModal"><i
                            class="mdi mdi-plus"></i> 新增</a>
                </div>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th>-</th>
                                <th>下载页标题</th>
                                <th>模板文件</th>
                                <th>app名称</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $data as $key=>$vo}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.site_title}</td>
                                <td>{$vo.template}</td>
                                <td>{$vo.appname}</td>
                                <td>
                                    <div class="btn-group">
                                        <a class="btn btn-xs btn-default m-r-5 edit-btn" href="/admin/appdown/edit/id/{$vo.id}" title="" data-toggle="tooltip" data-original-title="编辑">
                                            <i class="mdi mdi-pencil"></i>
                                        </a>
                                        <a class="btn btn-xs btn-default m-r-5 edit-btn" href="/code/{$vo.code}" title="" data-toggle="tooltip" data-original-title="下载">
                                            <i class="mdi mdi-arrow-down-bold"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                            {/foreach}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
    aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h6 class="modal-title" id="exampleModalLabel">新增下载页配置</h6>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label for="site_title">下载页标题</label>
                    <input type="text" class="form-control" id="site_title" placeholder="请输入下载页标题">
                </div>
                <div class="form-group">
                    <label for="template">模板文件</label>
                    <select class="form-control" id="template">
                        <option value="" disabled>请选择模板文件</option>
                        {foreach :getDir() as $key=>$value }
                        <option value="{$value}">{$value}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="form-group">
                    <label for="appid">appid</label>
                    <select class="form-control" id="appid">
                        <option value="" disabled>请选择app</option>
                        {foreach :query('app') as $key=>$value }
                        <option value="{$value['appid']}">{$value["appname"]}(appid:{$value['appid']})</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" id="shutdown" data-dismiss="modal">关闭</button>
                <button type="button" id="add" class="btn btn-w-sm btn-primary">保存</button>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    $("#add").click(function () {
        var l = $('#add').lyearloading({
            opacity: 0.2,
            spinnerSize: 'nm'
        });
        var site_title = $.trim($("#site_title").val());
        var template = $.trim($("#template").val());
        var appid = $.trim($("#appid").val());
        $.ajax({
            type: 'post',
            url: "{:url('Appdown/add')}",
            data: {
                'site_title': site_title,
                'template': template,
                'appid': appid,
            },
            dataType: "json",
            success: function (data) {
                l.destroy();
                if (data.code == 1) {
                    notify.success(data.msg,function () {
                        location.reload();
                    },1000);
                } else {
                    notify.error(data.msg);
                    $("#exampleModal").modal('hide');
                }
            },
            error: function () {
                l.destroy();
                notify.error("系统错误");
            }
        })
    });
</script>
{/block}